// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/broadcast/api/BroadcastTerminalApi'

import OneClass from '@api/broadcast/model/TerminalBaseReq'
import PassClass from '@api/broadcast/model/BroadcastingReq'
import SubmitClass from '@api/broadcast/model/BroadcastTerminalSetVolReq'

const CLIENT = CORE.grpcCLIENT(Client)

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async getOne({ id, microphoneId }, TIP = '查询单项') {
    const DTO = CORE.grpcDTO(OneClass, { id: [id] })
    const resp = await CORE.grpc(TIP, CLIENT, 'queryTerminalDetail', DTO)
    return { ...resp.content, microphoneId }
  },

  // —————————————————————————————— 通过 —————————————————————————————— //

  async pass(one, TIP = '通过') {
    const DTO = CORE.grpcDTO(PassClass, { ...one, terminalId: one.id })
    await CORE.grpc(TIP, CLIENT, 'broadcasting', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 提交 —————————————————————————————— //

  async submit({ id, volume }, TIP = '提交') {
    const DTO = CORE.grpcDTO(SubmitClass, { deviceId: [id], vol: volume })
    await CORE.grpc(TIP, CLIENT, 'broadcastTerminalSetVol', DTO)
    return CORE.grpcOK(TIP)
  },
}
